package offer;

import java.util.*;


public class EX6 {
    class ListNode{
        ListNode next;
        int val;
        ListNode(int x) { val = x; }
    }

    List<Integer> line= new ArrayList<Integer>();
    public int[] reversePrint(ListNode head) {
        help(head);
        int [] res = new int[line.size()];
        for (int i = 0; i < line.size(); i++) {
            res[i] = line.get(i);
        }
        return res;
    }
    public void help(ListNode head){
        if(head.next==null){
            line.add(head.val);
            return;
        }
        help(head.next);
        line.add(head.val);
        return;
    }
}
